import json
from .node import Node, Link

class Param:
    def __init__(self, name, mtype):
        self.name = name
        self.type = mtype

    def to_map(self):
        return {"name": self.name, "type": self.type}


class Widget:
    def __init__(self, wtype, name, init_value, prop={}):
        self.type = wtype
        self.name = name
        self.init_value = init_value
        self.prop = prop

    def to_map(self):
        return {
            "type": self.type,
            "name": self.name,
            "init_value": self.init_value,
            "prop": self.prop,
        }


class Model:
    def get_title(self) -> str:
        return ""

    def get_category(self) -> str:
        return ""

    def get_path(self) -> str:
        return self.get_category() + "/" + self.get_title()

    def get_in(self) -> list[Param]:
        return [Param("name", "text")]

    def get_out(self) -> list[Param]:
        return [Param("name", "text")]

    def get_widget(self) -> list[Widget]:
        return [Widget("text", "prop", "")]

    # 处理方法
    def process(self, node: Node, links: list[Link]) -> list[Link]:
        # 返回Link列表
        return []

    def to_json(self):
        return {
            "title": self.get_title(),
            "path": self.get_path(),
            "in": [m.to_map() for m in self.get_in()],
            "out": [m.to_map() for m in self.get_out()],
            "widget": [m.to_map() for m in self.get_widget()],
        }
